# vim:ts=4:sw=4:noet:
""" Support code """

import sys

class Struct:
	def __init__(self, **entries): self.__dict__.update(entries)

Enum = Struct

class CoreException:
	def __init__(self, msg, data=None):
		self.msg = msg
		self.data = data

	def __str__(self):
		if self.data:
			return "%s" % (self.msg)
		return self.msg

class Status:
	def __init__(self, options, outstream=sys.stdout):
		self.options = options
		self.outstream = outstream

	def error(self, msg, data=None):
		if (self.options["exceptions"]):
			raise CoreException(msg, data)
		else:
			self.outstream.write("ERROR: %s\n" % msg)
			sys.exit(1)

	def warning(self, msg):
		self.outstream.write("WARNING: %s\n" % msg)

	def info(self, msg):
		self.outstream.write("%s\n" % msg)

	def printNl(self, msg):
		self.outstream.write("%s\n" % msg)
	
	def printNnl(self, msg):
		self.outstream.write("%s" % msg)
